//
//  DBManager.h
//
//  Created by Christine on 3/23/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "FXEnum.h"
#import <Foundation/Foundation.h>
#import <sqlite3.h>

@interface DBManager : NSObject 
{
    sqlite3 *database;
}

+ (DBManager *)sharedDBManager;

- (sqlite3_stmt*) getStatement:(NSString*) sqlCommand;
- (void) endStatement:(sqlite3_stmt*) statement;
- (void) bindStatement:(sqlite3_stmt*) statement index:(int) index value:(NSObject*) value;
- (void) bindStatement:(sqlite3_stmt*) statement parameters:(NSArray*) parameters;
- (BOOL) executeSql:(NSString*) sqlCommand parameters:(NSArray*) parameters;
- (NSArray*) getSqlData:(NSString*) sqlCommand parameters:(NSArray*) parameters;
- (int) getLastRowID;


- (NSArray *)getRecentFileList;
- (void)removeRecentFile:(NSString *)path;
- (NSArray *)getFavoriteFileList;
- (void)removeFavoriteFile:(NSString *)path;
- (void)recordRecentFile:(NSString *)path modifiedDate:(NSDate *)modifiedDate lastViewDate:(NSDate *)viewedDate;
- (BOOL)isFavoriteFile:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)clearRecentTable;
- (void)clearRecentFile:(NSString *)path;
- (void)replaceRecentFileFrom:(NSString *)fromPath fromModifiedDate:(NSDate *)fromModifiedDate to:(NSString *)toPath toModifiedDate:(NSDate *)toModifiedDate;
- (NSString *)getCachePath:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (NSString *)getCachePathWithoutModifiedDate:(NSString *)path;
- (void)recordCachePath:(NSString *)path modifiedDate:(NSDate *)modifiedDate cachePath:(NSString *)cachePath;
- (void)removeCachePath:(NSString *)path;
- (void)replaceCacheFileFrom:(NSString *)fromPath fromModifiedDate:(NSDate *)fromModifiedDate to:(NSString *)toPath toModifiedDate:(NSDate *)toModifiedDate;
- (int)getVisitCount:(NSString *)path;
- (void)updateRecentModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)updateFavoriteModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)updateCachePathModifiedDate:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (int)getLastPage:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)recordLastPage:(NSString *)path modifiedDate:(NSDate *)modifiedDate pageNum:(int)pageNum needSync:(BOOL)needSync;
- (void)resetLastPageForAllFile;
- (PDF_DISPLAY_MODE)getLastDisplayMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)recordLastDisplayMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate displayMode:(PDF_DISPLAY_MODE)displayMode needSync:(BOOL)needSync;

- (PDF_DISPLAY_MODE)getPreviousDisplayMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate;
- (void)recordPreviousDisplayMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate displayMode:(PDF_DISPLAY_MODE)displayMode needSync:(BOOL)needSync;

- (CGPoint)getReadPosition:(NSString*)path modifiedDate:(NSDate*)modifiedDate;
- (void)recordReadPosition:(NSString*)path modifiedDate:(NSDate*)modifiedDate position:(CGPoint)position needSync:(BOOL)needSync;
    
- (float)getReadScale:(NSString*)path modifiedDate:(NSDate*)modifiedDate;
- (void)recordReadScale:(NSString*)path modifiedDate:(NSDate*)modifiedDate scale:(float)scale needSync:(BOOL)needSync;
    
- (NSArray *)getOpenedRemovableCacheFolderPriority;
- (NSArray *)getNotopenedRemovableCacheFolderPriority;
- (void)recordFavoriteFile:(NSString *)path fileName:(NSString *)fileName modifiedDate:(NSDate *)modifiedDate isFavorite:(BOOL)isFavorite;
- (void)recordLastCropMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate cropMode:(int)cropMode cropInsets:(NSString *)cropInsets;
- (NSArray *)getLastCropMode:(NSString *)path modifiedDate:(NSDate *)modifiedDate;

//JavaScript
- (BOOL)setJavaScriptData:(NSString*)key value:(NSString*)value;
- (NSString*)getJavaScriptData:(NSString*)key;

@end
